<?php
if(isset($_GET['reg']) && isset($_GET['status']) && isset($_GET['msisdn'])){
$conexion = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic", $conexion);
echo	$_GET['reg'].",".$_GET['status'].",".$_GET['msisdn'];

mysql_query("INSERT INTO  `test` (  `tipo` ,  `reg` ,  `tel` ) VALUES ('".$_GET['status']."',  '".$_GET['reg']."',  '".$_GET['msisdn']."');", $conexion);	

$telefono=$_GET['msisdn'];
$result1= mysql_query("SELECT * FROM telefonos where telefono = '".$telefono."'", $conexion) or die(mysql_error());


if (mysql_num_rows($result1)){ 
while ($row1 = @mysql_fetch_array($result1)){
	$id_telefono = $row1['id'];

}
}

$reg = explode('-', $_GET['reg']);

if($reg[0] == 'c'){
mysql_query("UPDATE `envios`  SET `hora` = CURTIME(),  `estado` = 1  WHERE `envios`.`id_telefono`=".$id_telefono." AND envios.`id_conv`=".$reg[1]." AND envios.`reg`=".$reg[2], $conexion);
echo "actualizado"	;
}
else{
mysql_query("UPDATE   `envios`  SET `hora` = CURTIME(),    `estado` = 1 WHERE `envios`.`id_telefono`=".$id_telefono." AND envios.`id_conv` is null AND envios.`reg`=".$reg[0], $conexion);
echo "actualizado"	;
}




mysql_close();

}

if(isset($_POST['reg']) && isset($_POST['status']) && isset($_POST['msisdn'])){
$conexion = mysql_connect("localhost", "admin", "Xurpas123");
mysql_select_db("smsnic", $conexion);
echo	$_POST['reg'].",".$_POST['status'].",".$_POST['msisdn'];

mysql_query("INSERT INTO  `test` (  `tipo` ,  `reg` ,  `tel` ) VALUES ('".$_POST['status']."',  '".$_POST['reg']."',  '".$_POST['msisdn']."');", $conexion);	

$telefono=$_POST['msisdn'];
$result1= mysql_query("SELECT * FROM telefonos where telefono = '".$telefono."'", $conexion) or die(mysql_error());


if (mysql_num_rows($result1)){ 
while ($row1 = @mysql_fetch_array($result1)){
	$id_telefono = $row1['id'];

}
}

$reg = explode('-', $_POST['reg']);

if($reg[0] == 'c'){
mysql_query("UPDATE `envios`  SET (`hora` = CURTIME(),  `estado` = 1 ) WHERE `envios`.`id_telefono`=".$id_telefono." AND envios.`id_conv`=".$reg[1]." AND envios.`reg`=".$reg[2], $conexion);
echo "actualizado"	;
}
else{
mysql_query("UPDATE   `envios`  SET (    `hora` = CURTIME(),    `estado` = 1  ) WHERE `envios`.`id_telefono`=".$id_telefono." AND envios.`id_conv` is null AND envios.`reg`=".$reg[0], $conexion);
echo "actualizado"	;
}




mysql_close();

}

?>